﻿using System;
using System.Runtime.InteropServices;
using System.Diagnostics;

namespace ShpMergerGUI
{
    internal class ConsoleShower
    {
        public void RunConsole()
        {           
            AllocConsole();
            //mask close button
            IntPtr windowHandle = FindWindow(null, Process.GetCurrentProcess().
                    MainModule.FileName);
            IntPtr closeMenu = GetSystemMenu(windowHandle, IntPtr.Zero);
            uint SC_CLOSE = 0xF060;
            RemoveMenu(closeMenu, SC_CLOSE, 0x0);

            //run console exe
            ShpMergerConsole.Program.RunConsole();
            FreeConsole();
        }

        [DllImport("kernel32.dll")]
        public static extern bool AllocConsole();
        [DllImport("kernel32.dll", EntryPoint = "FreeConsole")]
        public static extern bool FreeConsole();
        [DllImport("user32.dll", EntryPoint = "FindWindow")]
        extern static IntPtr FindWindow(string lpClassName, string lpWindowName);
        [DllImport("user32.dll", EntryPoint = "GetSystemMenu")]
        extern static IntPtr GetSystemMenu(IntPtr hWnd, IntPtr bRevert);
        [DllImport("user32.dll", EntryPoint = "RemoveMenu")]
        extern static IntPtr RemoveMenu(IntPtr hMenu, uint uPosition, uint uFlags);          
    }
}
